<template>
	<view class="content">
		<view class="input-title">
			<view class="title">建议反馈标题:</view>
			<input @input="titleInput" class="input" maxlength="100" focus placeholder="请输入标题" />
		</view>

		<view class="input-content">
			<view class="title">建议反馈内容:</view>
			<textarea @input="textareaInput" class="textarea" maxlength="500" placeholder="请输入内容" />
		</view>

		<view class="submit">
			<button class="submit-btn" @click="submitClick" type="primary">提交</button>
		</view>
		<view class="tips">
			<view class="cnt-tip" v-if="usertype != 2">
				<br>您的建议反馈对我们至关重要，为了更好的用户体验，诚邀您提出应用建议反馈，我们会用心倾听，期待您畅所欲言。
			</view>
			<view class="cnt-tip" v-if="usertype == 2">
				您的建议反馈对我们至关重要，为了更好的用户体验，诚邀您提出应用建议反馈，我们会用心倾听，期待您畅所欲言。首次建议将会奖励1000积分。
			</view>
			  <view class="wx-tip"> 【此投诉为本小程序自有投诉建议渠道，非微信官方投诉渠道】</view>
		</view>
	</view>
</template>
<script>
    import {
        getTotalUserScore,
        getUserScoreFromCloud,
        saveUserTotalScoreToCloud,
        getUserScore,
        addUserScore,
        saveUserAddScoreToLocal,
        SignInGetScore,
        SignInGetScoreLocal,
        saveUserCloudScoreToLocal
    } from '../../store/scoreManager.js';
    import { onLoad, onShow, onReady, onBackPress } from "@dcloudio/uni-app";

    export default {
        data() {
            return {
                suggest: {
                    sTitle: "",
                    sContent: ""
                },
                sTitle: "",
                sContent: "",
                userInfo: {},
                usertype: false
            };
        },
        onLoad: function (e) {
            this.usertype = e.usertype;
        },
        methods: {
            async submitClick() {
                const db = uniCloud.database();
                uni.showLoading({
                    title: "提交中...",
                    mask: true,
                });

                const user = await getUserScoreFromCloud();

                if (user) {
                    delete user._id;
                    this.suggest = Object.assign(this.suggest, user);
                }

                db.collection("user_suggest").add(this.suggest).then((info) => {
                    uni.hideLoading();
                    uni.showToast({
                        title: "感谢您的建议反馈！",
                        icon: "none"
                    });
                    const isFirst = uni.getStorageSync("sugeest");
                    if (!isFirst && this.usertype == 2) {
                        saveUserAddScoreToLocal(1000);
                        uni.setStorageSync("sugeest", "1");
                    }
                    setTimeout(() => {
                        uni.navigateBack({
                            success: () => { },
                            fail: () => {
                                uni.reLaunch({
                                    url: '/pages/index/shouye'
                                });
                            }
                        });
                    }, 2000);
                }).catch((e) => {
                    console.log("addError:", e);
                    uni.hideLoading();
                    uni.showToast({
                        title: "提交失败，请稍后再试",
                        icon: "none"
                    });
                });
            },
            textareaInput: function (e) {
                this.suggest.sContent = e.detail.value;
            },
            titleInput: function (e) {
                this.suggest.sTitle = e.detail.value;
            }
        }
    };
</script>

// <!-- // scss 语言类型  scoped css样式的类名仅限当前页面 不污染其它页面 -->
<style lang="scss" scoped>
	.content {
		position: relative;
		width: 100%;
		height: 100%;

		.input-title {
			position: relative;
			margin-top: 20rpx;
			width: 100%;
			height: 200rpx;
			padding: 20rpx;

			.title {
				margin-top: 10rpx;
				height: 30rpx;
				margin-left: 30rpx;
				width: 70%;
				font-size: 30rpx;
				font-weight: 600;
			}

			.input {
				margin-top: 20rpx;
				padding: 20rpx;
				margin-left: 20rpx;
				background-color: $uni-bg-color-grey;
				width: 100%;
				height: 50rpx;
			}
		}

		.input-content {
			position: relative;
			margin-top: 20rpx;
			width: 100%;
			height: 400rpx;
			padding: 20rpx;

			.title {
				margin-top: 10rpx;
				height: 30rpx;
				margin-left: 30rpx;
				width: 70%;
				font-size: 30rpx;
				font-weight: 600;
			}

			.textarea {
				margin-top: 20rpx;
				padding: 20rpx;
				margin-left: 20rpx;
				margin-right: 20rpx;
				background-color: $uni-bg-color-grey;
				width: 100%;
				height: 300rpx;
			}
		}

		.submit {
			display: flex;
			margin-top: 60rpx;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 120rpx;

			.submit-btn {
				width: 400rpx;

			}
		}
		.tips{
			.wx-tip{
				
				text-align: center;
				color: black;
				font-weight: 800;
				margin-top: 20rpx;
			}
			.cnt-tip{
				text-indent: 41px;
				text-align: center;
				cursor: default;
				color: #333;
				font-weight: 400;
			}
			margin-left: 40rpx;
			margin-right: 20rpx;
			height: 180rpx;
			margin-top: 50rpx;
			color: $uni-color-subtitle;
		}
	}
</style>